package com.zlll.winner.controller.media;


import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.zlll.winner.LoginUser;
import com.zlll.winner.business.model.media.MediaNewList;
import com.zlll.winner.business.service.media.IMediaNewListService;
import com.zlll.winner.common.BaseController;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 论坛专题管理
 */
@LoginUser
@RestController
@RequestMapping(value = "/media/new/list")
public class MediaNewListController extends BaseController {

    @Reference
    private IMediaNewListService mediaNewListService;

    /**
     * 分页列表
     * @param params
     * @return
     */
    @PostMapping(value = "page")
    public Object page(@RequestBody JSONObject params){
        Integer pageNo = params.getInteger("pageNo");
        Integer pageSize = params.getInteger("pageSize");
        Assert.notNull(pageNo,"pageNo不能为空");
        Assert.notNull(pageSize,"pageSize不能为空");
        return mediaNewListService.fetchNewListPage(params);
    }

    /**
     * 保存
     * @param params
     * @return
     */
    @PostMapping(value = "save")
    public Object save(@RequestBody JSONObject params){
        return mediaNewListService.saveNewList(params,getUser());
    }


    /**
     * 更新
     * @param params
     * @return
     */
    @PostMapping(value = "update")
    public Object update(@RequestBody JSONObject params){

        Long id = params.getLong("id");
        String bigImage = params.getString("bigImage");
        String smallImage = params.getString("smallImage");
        String showTitle = params.getString("showTitle");
        String showTopic = params.getString("showTopic");
        String hostOneName = params.getString("hostOneName");
        String hostTwoName = params.getString("hostTwoName");
        Long hostOneId = params.getLong("hostOneId");
        Long hostTwoId = params.getLong("hostTwoId");

        MediaNewList mediaNewList = new MediaNewList();
        mediaNewList.setId(id);
        mediaNewList.setBigImage(bigImage);
        mediaNewList.setSmallImage(smallImage);
        mediaNewList.setHostTwoName(hostTwoName);
        mediaNewList.setHostOneName(hostOneName);
        mediaNewList.setShowTitle(showTitle);
        mediaNewList.setShowTopic(showTopic);
        mediaNewList.setHostOneId(hostOneId);
        mediaNewList.setHostTwoId(hostTwoId);
        mediaNewList.setUpdateTime(System.currentTimeMillis());
        mediaNewList.setUpdateUser(getUser().getUserName());

        mediaNewListService.updateById(mediaNewList);

        return mediaNewList;
    }

    /**
     * 删除
     * @param params
     * @return
     */
    @PostMapping(value = "delete")
    public Object delete(@RequestBody JSONObject params){
        Long id = params.getLong("id");
        return mediaNewListService.deleteNewList(id,getUser());
    }

    /**
     * 详情
     * @param params
     * @return
     */
    @PostMapping(value = "details")
    public Object details(@RequestBody JSONObject params){
        return null;
    }


    /**
     * 复制昨天节目清单
     * @param params
     * @return
     */
    @PostMapping(value = "copy")
    public Object copyYesterday(@RequestBody JSONObject params){
        return mediaNewListService.copyYesterdayShow(params,getUser());
    }

}
